//
//  KRLUserModel.m
//  KaraLive
//
//  Created by Zhijia Zhong on 2018/9/14.
//  Copyright © 2018年 naxigoren. All rights reserved.
//

#import "KRLUserModel.h"

@implementation KRLUserModel

@synthesize userToken = _userToken;

+ (instancetype)sharedUser {
    static KRLUserModel *_sharedUser;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedUser = [[KRLUserModel alloc] init];
    });
    return _sharedUser;
}

- (NSString *)userToken {
    if (_userToken.length > 0) {
        return _userToken;
    } else {
        NSString *userToken = [[NSUserDefaults standardUserDefaults] valueForKey:@"KRLUserToken"];
        if (userToken.length > 0) {
            _userToken = userToken;
            return _userToken;
        } else {
            return @"";
        }
    }
}

- (void)updateUserToken:(NSString *)userToken {
    _userToken = userToken;
    
    [[NSUserDefaults standardUserDefaults] setValue:userToken forKey:@"KRLUserToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

@end
